﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Reflection;

using Microsoft.Surface.Presentation.Input;

using ScrumTable.Common.Logging;

#endregion

namespace ScrumTable.UI.View.WinTouch.Util
{

    /// <summary>
    /// DropDropUtil Util
    /// </summary>
    public class SurfaceUtil
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------
        
        private static volatile bool _isSurfaceRunningChecked = false;
        private static volatile bool _isSurfaceRunning = false;

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Detects whether a surface hardware is running.
        /// </summary>
        /// <returns>Returns true if a real surface hardware is available.</returns>
        public static bool IsSurfaceRunning()
        {
            return EnsureSurfaceIsRunning();
        }

        private static bool EnsureSurfaceIsRunning()
        {
            if (!_isSurfaceRunningChecked)
            {
                _isSurfaceRunningChecked = true;
                try
                {
                    _isSurfaceRunning = CheckSurfaceIsRunning();
                }
                catch (Exception e)
                {
                    _isSurfaceRunning = false;
                    Logger<SurfaceUtil>.Warn("An error occured while checking if a surface hardware is available.", e);
                }
            }
            return _isSurfaceRunning;
        }

        private static bool CheckSurfaceIsRunning()
        {
            return InteractiveSurface.PrimarySurfaceDevice.IsTagRecognitionSupported;
        }

        #endregion
    }
}
